<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>所有会员卡列表</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!-- Bootstrap 3.3.4 -->
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <!-- FontAwesome 4.3.0 -->
    <link href="${ctx}/static/plugins/datatables/css/matrix-style.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/css/basic.css" rel="stylesheet" type="text/css">
    <style type="text/css">
		.right_btn{
			float: right;
		}
		.left_btn{
			float:left;
			padding:10px 0px 10px 20px
		}
		.form-group{
			display: inline-flex;
		}
		.s_table{
			width: 100%;
			padding: 20px 20px 20px 0px;
		}
		.s_table label{font-weight: normal;}
		.s_table tr{
			height: 50px;
			margin: 10px;
		}
		.form-control{
			width: 80%;
		}
		.right_btn{
			float: right;
			margin-right: 5%;
		}
		.label{font-weight: 500;}
		.s_table td{
			font-weight: normal;
			padding-right: 20px;
			max-width: 200px;
			text-align: right;
		}
		.isMarketing_td .isMarketing_td{
			text-align: left;
		}
		.div_hidden{display: none}
    </style>
</head>
<body>
<div class="wrapper">
	<div class="widget-box">
		<div class="widget-title">
		   <h5>请输入查询条件</h5>
		</div>
		<div class="widget-content nopadding">
			<table class="s_table">
				<tr>
					<td>
						<label for="member_phone">手机号：</label>
					</td>
					<td>
						<input type="text" class="form-control" id="member_phone" placeholder="手机号">
					</td>
					<td>
						<label for="member_iccode">IC卡号：</label>
					</td>
					<td>
						<input type="text" class="form-control" id="member_iccode" placeholder="IC卡号">
					</td>
					<td>
						<label for="bar_code">条形码：</label>
					</td>
					<td>
						<input type="text" class="form-control" id="bar_code" placeholder="条形码">
					</td>
				</tr>
				<tr>
					<td> <label>状态：</label></td>
					<td> 
						<select class="form-control" name="status" id="status">
							 <option value="">全部</option>
		                     <option value="1">正常</option>
		                     <option value="3">挂失</option>
		                     <option value="4">冻结</option>
                 		</select>
	                 </td>
	                 <td colspan="4">
						<div class="right_btn">
								<button type="button" id="btn_query" class="btn btn-primary" onClick="query()">查询</button>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	
	 <div class="row">
		 <div class="col-xs-12">
		 	<div class="box">
		 		 <div class="box-header">
	                 <h3 class="box-title">会员卡列表</h3>
	             </div>
	             <!-- 列表 -->
	             <div class="box-body table-responsive">
	             	<table id="dataTables" class="table table-bordered table-hover">
	             	</table>
	             </div>
		 	</div>
		 </div>
	</div>
</div>
<!-- jQuery 2.1.4 -->
<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!--Bootstrap v3.3.4-->
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<!--bootstrap-datepicker-->
<script src="${ctx}/static/plugins/My97DatePicker/datePicker/WdatePicker.js"></script>
<!-- datatable -->
<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js" type="text/javascript"></script>
<script src="${ctx}/static/plugins/layer/layer.js"></script>
<script>
   var tb;
   $(function () {
		//列表初始化
		tb = $('#dataTables').dataTable({
				"bServerSide": true,
				"sPaginationType": "full_numbers",
				"bJQueryUI": true,
				"sDom": '<"">t<"F"ip>',
				"sAjaxSource": "${ctx}/api/membercard/alllistPage", //ajax调用接口
				"aoColumnDefs": [{sDefaultContent: '',aTargets: [ '_all' ]}],
	       		"aoColumns": [
					  	{ "sTitle" : "编号","mData": "num" ,"class":"sClass"},
		                { "sTitle" : "联系人","mData": "memberName","class":"sClass" },
		                { "sTitle" : "手机号","mData": "memberPhone","class":"sClass" },
		                { "sTitle" : "IC卡号","mData": "innerCode","class":"sClass" },
		                { "sTitle" : "条形码","mData": "outerCode","class":"sClass" },
		                { "sTitle" : "发卡时间","mData": "createTime","class":"sClass" },
		                { "sTitle" : "挂失时间","mData": "reportTime","class":"sClass" },
		                { "sTitle" : "状态","mData": "status","class":"sClass" ,"mRender":function(data, type, full){
		                		var text;
		                    	if(full.status==1){
		                    		text="<font color='blue'>正常</font>";
		                    	}else if(full.status==3){
		                    		text="<font color='green'>挂失</font>";
		                    	}else if(full.status==4){
		                    		text="<font color='green'>冻结</font>";
		                    	}
	                    		return text;
        					}
		                },
		                {"sTitle" : "操作","mData" : "id", "mRender" : function ( data, type, full ) {
		                	      var text;
		                		  if(full.status == 1 || full.status == 4){
		                			  text = '<div class="btn-group" style="text-align:left;"><button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">操作 <span class="caret"></span></button>';
									  text = text+'<ul class="dropdown-menu" role="menu">';
									  if(full.status == 1){
										  text += "<li><a href='javascript:frozenMemberCard("+full.icCardId+")'>冻结</a></li>";
									  }else if(full.status == 4){
										  text += "<li><a href='javascript:relieveMemberCard("+full.icCardId+")'>解除冻结</a></li>";
									  }
									  text = text + '</ul></div>';
		                		  }
								  return text;
							  } 
		                }
	            ],
		        "oLanguage" : {
		           "sProcessing" : "数据加载中······",
		           "sLengthMenu" : "显示 _MENU_ 条记录",
		           "sZeroRecords" : "没有您要搜索的内容！",
		           "sEmptyTable" : "列表中无数据存在！",
		           "sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
		           "sInfoEmpty" : "显示 0 到 0 条记录",
		           "sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
		           "oPaginate" : {
		               "sFirst" : "首页",
		               "sPrevious" : "上一页",
		               "sNext" : "下一页",
		               "sLast" : "末页"
		           }
		        },
		        "fnServerData" : function ( sSource, aoData, fnCallback, oSettings ) {
					oSettings.jqXHR = $.ajax( {
						"dataType" 	: 'json',
						"type" 		: "post",
						"async"     : 'false',
						"url" 		: sSource,
						"data" 		: {
							'pageNum': (aoData[3].value/aoData[4].value)+1,
							'pageSize' :  aoData[4].value,
							'memberPhone' : $('#member_phone').val(),
							'innerCode' : $('#member_iccode').val(),
							'outerCode' : $('#bar_code').val(),
							'status' : $('#status').val()
						}, 
						"success"	: fnCallback
					} );
				},
		  });
   });
   //条件查询重新加载数据
   function query() {
 	    tb.fnDraw();
   };
	//冻结
   function frozenMemberCard(icCardId){
	   layer.confirm('是否冻结会员卡？', {
		   btn: ['是','否'] //按钮
		 }, function(){
			 var url = "${ctx}/api/membercard/frozenMemberCard";
			   $.post(url,{"icCardId":icCardId},function(data){
				   if(data.code == "200"){
					   layer.alert("冻结成功");
					   tb.fnDraw();
				   }else{
					   layer.alert("冻结会员卡失败");
				   }
		     })
	   });
   }
	//解除冻结
   function relieveMemberCard(icCardId){
	   layer.confirm('是否解冻会员卡？', {
		   btn: ['是','否'] //按钮
		 }, function(){
			 var url = "${ctx}/api/membercard/relieveMemberCard";
			   $.post(url,{"icCardId":icCardId},function(data){
				   if(data.code == "200"){
					   layer.alert("解冻成功");
					   tb.fnDraw();
				   }else{
					   layer.alert("解冻会员卡失败");
				   }
		     })
	   });
   }
</script>
</body>
</html>